package com.group2.equipment.utils;


import lombok.Data;

@Data
public class Result<T> {
    // 是否成功
    private Boolean flag;
    // 返回码
    private Integer code;
    // 返回信息
    private String message;
    // 返回数据
    private T data;

    public Result() {
    }

    public Result(Boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result(Boolean flag, Integer code, String message, T data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 设置返回成功
     */
    public void setSuccess() {
        this.flag = true;
        this.code = StatusCode.OK.getCode();
        this.message = StatusCode.OK.getMsg();
    }

    /**
     * 设置返回失败
     */
    public void setError() {
        this.flag = false;
        this.code = StatusCode.ERROR.getCode();
        this.message = StatusCode.ERROR.getMsg();
    }
}